use axum::{response::IntoResponse, Form};

use crate::domain::class::Class;
use crate::{service::class_service, ApiResponse};

pub async fn save(class: Form<Class>) -> impl IntoResponse {
    let mut class = class.0;
    let id = class_service::save(&mut class).await.unwrap();
    ApiResponse::from(id)
}

pub async fn del(class: Form<Class>) -> impl IntoResponse {
    let class = class.0;
    assert!(class.id.unwrap_or_default() > 0, "参数错误");
    let _ = class_service::delete(&class).await;
    ApiResponse::from(1)
}
